package com.ruoyi.period.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.period.domain.RentalPeriod;
import com.ruoyi.period.service.IRentalPeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 可选租期管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/period/period")
public class RentalPeriodController extends BaseController
{
    @Autowired
    private IRentalPeriodService rentalPeriodService;

    /**
     * 查询可选租期管理列表
     */
    @PreAuthorize("@ss.hasPermi('period:period:list')")
    @GetMapping("/list")
    public TableDataInfo list(RentalPeriod rentalPeriod)
    {
        startPage();
        List<RentalPeriod> list = rentalPeriodService.selectRentalPeriodList(rentalPeriod);
        return getDataTable(list);
    }

    /**
     * 导出可选租期管理列表
     */
    @PreAuthorize("@ss.hasPermi('period:period:export')")
    @Log(title = "可选租期管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RentalPeriod rentalPeriod)
    {
        List<RentalPeriod> list = rentalPeriodService.selectRentalPeriodList(rentalPeriod);
        ExcelUtil<RentalPeriod> util = new ExcelUtil<RentalPeriod>(RentalPeriod.class);
        util.exportExcel(response, list, "可选租期管理数据");
    }

    /**
     * 获取可选租期管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('period:period:query')")
    @GetMapping(value = "/{rentalPeriodId}")
    public AjaxResult getInfo(@PathVariable("rentalPeriodId") Long rentalPeriodId)
    {
        return success(rentalPeriodService.selectRentalPeriodByRentalPeriodId(rentalPeriodId));
    }

    /**
     * 新增可选租期管理
     */
    @PreAuthorize("@ss.hasPermi('period:period:add')")
    @Log(title = "可选租期管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RentalPeriod rentalPeriod)
    {
        return toAjax(rentalPeriodService.insertRentalPeriod(rentalPeriod));
    }

    /**
     * 修改可选租期管理
     */
    @PreAuthorize("@ss.hasPermi('period:period:edit')")
    @Log(title = "可选租期管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RentalPeriod rentalPeriod)
    {
        return toAjax(rentalPeriodService.updateRentalPeriod(rentalPeriod));
    }

    /**
     * 删除可选租期管理
     */
    @PreAuthorize("@ss.hasPermi('period:period:remove')")
    @Log(title = "可选租期管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{rentalPeriodIds}")
    public AjaxResult remove(@PathVariable Long[] rentalPeriodIds)
    {
        return toAjax(rentalPeriodService.deleteRentalPeriodByRentalPeriodIds(rentalPeriodIds));
    }
}
